var module = angular.module('calendarioModule', ['ui.calendar','agendana']);
module.controller('CalendarioCtrl',['$scope','ajaxManager',function($scope,ajaxManager) {

    $scope.eventsF = function (desde, hasta, timezone, callback) {
        var url_fuente = this.getView().name=='month'? ajax_urls.JORNADAS_CON_TURNOS: ajax_urls.TURNOS_CALENDARIO; 
        ajaxManager.ajax_get($scope,url_fuente,{params:{desde:desde.format(),hasta:hasta.format()}},callback);
    };
    
    $scope.calendarActualView = 'month';
    
    /* config object */
    $scope.uiConfig = {
      calendar:{
          viewRender: function(view) {
              if($scope.calendarActualView != view.name){
                  $scope.calendarActualView = view.name;
                  this.calendar.refetchEvents();
              }
            }
      }
    };

    /* event sources array*/
    $scope.eventSources = [$scope.eventsF];
}]);

angular.element(document).ready(function() {
    angular.bootstrap(document, ['calendarioModule']);
});
